package com.zhkj.txg.module.group.adapter

import android.graphics.Paint
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.utils.AccountManager
import com.zhkj.txg.R
import com.zhkj.txg.module.group.entity.GroupProduct
import com.zhkj.txg.utils.ImageUtils

class GroupListAdapter(type: Int = TYPE_GROUP) :
    BaseQuickAdapter<GroupProduct, BaseViewHolder>(R.layout.item_group_list), LoadMoreModule {

    companion object {
        val TYPE_GROUP = 1
    }

    var mType: Int

    init {
        mType = type
    }

    override fun convert(helper: BaseViewHolder, item: GroupProduct) {
        val imageView = helper.setText(R.id.tvCateProductName, item.goods_name)
            .setVisible(R.id.tvCateProductTag, item.is_new)
            .setVisible(R.id.text_count, item.people != null)
            .setText(R.id.text_count, "${item?.people}人拼")
            .setText(R.id.tvCateProductTagSecond, if (mType == TYPE_GROUP) "立即开团" else "立即抢购")
            .setText(
                R.id.tvCateProductPrice,
                if (item.group_price != null) "￥${item.group_price}/" else "￥${item.price}/"
            )
            .getView<ImageView>(R.id.ivCateProduct)
        helper.getView<TextView>(R.id.tvCateProductMarketPrice).apply {
            if (AccountManager.isMember() && item.share_earn.isNotEmpty() && item.share_earn != "0") {
                setTextColor(ContextCompat.getColor(context, R.color.colorPrimary))
                paint.flags = Paint.ANTI_ALIAS_FLAG
                text = "赚${item.share_earn}"
            } else {
                setTextColor(ContextCompat.getColor(context, R.color.colorLightText))
                paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
                paint.isAntiAlias = true
                text = "￥${item.market_price}"
            }
        }
        ImageUtils.loadRoundCornerImage(context, imageView, item.image)
    }
}
